<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>叠数之和</title>
</head>
<body>
    <script>

        //每位数为5
        var a = 2;
        //位数初始化
        var num = 0;
        //初始化和
        var total = 0;


        for(var n=1;n<=4;n++){
            //每执行一次，求出更高位的数
            num = num * 10 + a;
            console.log(n + '位每' + a + '：',num);
            //累加
            total += num;
        }
        console.log('循环' + (n-1) + '次，位数为' + a + '的叠数之和为：',total);


    </script>
</body>
</html>